#ifdef __src
	#define EXTERN
#else 
	#define EXTERN extern
#endif 

// define error no
#define Toset_OK			 0
#define Comm_Err			-1
#define Reader_Err			-2
#define No_SF_Author		-3
#define No_MJ_Author		-4
#define Para_Err			-5
//#define TimesOut_Err		-6
#define No_Card				-7
#define No_MJ_SysCard		-8
#define No_XF_SysCard		-9
#define SysCard_Err			-10
#define UserCard_Err		-11
#define ReadCard_Err		-12
#define WriteCard_Err		-13
#define CreateLicence_Err	-14
#define Not_Identify		-15
#define Bcc_Err             -16
//#define Not_SysCard         -17
//#define Not_DevInitCard     -18
#define Not_OptCard         -19
#define Not_UserCard        -20
#define No_Lic_Err			-21
#define Not_Mifare1Card     -22
#define Not_OurSystem       -23
#define No_Author           -24

#define RST_Card			-100


// define const
#define MJXT		1
#define SFXT		2
#define MJSF		3

#define MJ_Sec		2
#define SF_Sec		1

// define varible
EXTERN int Mjxt_author;
EXTERN int Sfxt_author;

// define function
extern "C"
{
EXTERN HANDLE __stdcall OpenComm(int CommPort);
EXTERN    int __stdcall CloseComm(HANDLE icdev);
EXTERN    int __stdcall Check_Reader(HANDLE icdev);
EXTERN	  int __stdcall Load_Author(char *filename);
EXTERN	  int __stdcall Get_System(LPCSTR CommPassword,LPSTR UserPassword);
EXTERN    int __stdcall Init_SysCard(HANDLE icdev,LPCSTR UserPassword,int SysType,int MJSector,int MJCardType,int SFSector,LPSTR CommPassword);
EXTERN    int __stdcall Init_Pos_UserCard(HANDLE icdev,unsigned long Serno,LPCSTR Cardno,int UserType,int opt_num,unsigned long max_use,int max_times,LPCSTR user_password,unsigned long * CardSerno,int WaitTime,int li_sec);
EXTERN    int __stdcall RST_Pos_OPTCard(HANDLE icdev,unsigned int CardSerno,int WaitTime);
EXTERN    int __stdcall RST_Pos_UserCard(HANDLE icdev,unsigned int CardSerno,int WaitTime);
EXTERN	  int __stdcall WRT_Pos_UserCard(HANDLE icdev,int Value,unsigned long CardSerno,int *Count,int WaitTime);
EXTERN    int __stdcall Query_Pos_Card(HANDLE icdev,LPINT CardType,LPINT OPT_Num,LPINT Serno,LPSTR Cardno,unsigned long * CardSerno,LPINT Value,LPINT Count, LPINT UserType,int WaitTime);

EXTERN	  int __stdcall Hw_Init_UserCard(HANDLE icdev,long a_val1,long a_val2,long a_val3,unsigned long *a_nkh,unsigned char *a_nkhh);
EXTERN    int __stdcall Hw_Rst_UserCard(HANDLE icdev,unsigned long *a_nkh,unsigned char *a_nkhh);
EXTERN    int __stdcall Hw_Red_UserCard(HANDLE icdev,unsigned long *a_kh,unsigned long *a_val1,unsigned long *a_val2,unsigned long *a_val3,unsigned int *a_klb,unsigned int *a_xkf,unsigned long *a_nkh,unsigned char *a_nkhh);
EXTERN    int __stdcall Hw_Set_UserAmount1(HANDLE icdev,unsigned long a_val1,unsigned long *a_nkh,unsigned char *a_nkhh);
EXTERN    int __stdcall Hw_Set_UserAmount2(HANDLE icdev,unsigned long a_val2,unsigned long *a_nkh,unsigned char *a_nkhh);
EXTERN    int __stdcall Hw_Set_UserAmount3(HANDLE icdev,unsigned long a_val2,unsigned long *a_nkh,unsigned char *a_nkhh);
EXTERN    int __stdcall Hw_Red_Kai(HANDLE icdev,unsigned long *a_val,unsigned long *a_nkh,unsigned char *a_nkhh);
EXTERN    int __stdcall Hw_Wrt_Kai(HANDLE icdev,unsigned long a_val,unsigned long *a_nkh,unsigned char *a_nkhh);
}

void asc_to_bcd (unsigned char *bcd_buf ,unsigned char *ascii_buf ,int conv_len ,unsigned char type );
void bcd_to_asc(unsigned char * ascii_buf ,unsigned char *bcd_buf ,int conv_len ,unsigned char type);
void f_initkey(unsigned char *a_snr);

#undef EXTERN